/*
   @Copyright:LintCode
   @Author:   tjyemail
   @Problem:  http://www.lintcode.com/problem/min-stack
   @Language: C++
   @Datetime: 16-02-09 08:17
   */

class MinStack {
	stack<int> diff;
	int min_ele;

public:
	MinStack() {
		// do initialization if necessary
	}

	void push(int number) {
		// write your code here
		if (diff.size()<1){
			diff.push(0);
			min_ele = number;
		}
		else{
			diff.push(number-min_ele);
			if (min_ele>number) min_ele = number;
		}
	}

	int pop() {
		// write your code here
		if (diff.size()<1) return 0;
		int d = diff.top();
		diff.pop();
		if (d<0) min_ele -= d;
		return min_ele+d;
	}

	int min() {
		// write your code here
		return min_ele;
	}
};

